package b.g.b;

import java.util.Arrays;

/* compiled from: ArrayLinkedVariables */
public class a implements b.g.b.b.a {
    public int a = 0;
    public final b b;
    public final c c;
    public int d = 8;
    public int[] e = new int[8];
    public int[] f = new int[8];
    public float[] g = new float[8];
    public int h = -1;
    public int i = -1;
    public boolean j = false;

    public a(b bVar, c cVar) {
        this.b = bVar;
        this.c = cVar;
    }

    public float a(int i) {
        int i2 = this.h;
        int i3 = 0;
        while (i2 != -1 && i3 < this.a) {
            if (i3 == i) {
                return this.g[i2];
            }
            i2 = this.f[i2];
            i3++;
        }
        return 0.0f;
    }

    public void b(g gVar, float f, boolean z) {
        if (f <= -0.001f || f >= 0.001f) {
            int i = this.h;
            int i2;
            int[] iArr;
            if (i == -1) {
                this.h = 0;
                this.g[0] = f;
                this.e[0] = gVar.b;
                this.f[0] = -1;
                gVar.l++;
                gVar.a(this.b);
                this.a++;
                if (!this.j) {
                    i2 = this.i + 1;
                    this.i = i2;
                    iArr = this.e;
                    if (i2 >= iArr.length) {
                        this.j = true;
                        this.i = iArr.length - 1;
                    }
                }
                return;
            }
            int[] iArr2;
            int i3 = 0;
            int i4 = -1;
            while (i != -1 && i3 < this.a) {
                int[] iArr3 = this.e;
                int i5 = iArr3[i];
                int i6 = gVar.b;
                if (i5 == i6) {
                    float[] fArr = this.g;
                    float f2 = fArr[i] + f;
                    if (f2 > -0.001f && f2 < 0.001f) {
                        f2 = 0.0f;
                    }
                    fArr[i] = f2;
                    if (f2 == 0.0f) {
                        if (i == this.h) {
                            this.h = this.f[i];
                        } else {
                            iArr = this.f;
                            iArr[i4] = iArr[i];
                        }
                        if (z) {
                            gVar.b(this.b);
                        }
                        if (this.j) {
                            this.i = i;
                        }
                        gVar.l--;
                        this.a--;
                    }
                    return;
                }
                if (iArr3[i] < i6) {
                    i4 = i;
                }
                i = this.f[i];
                i3++;
            }
            int i7 = this.i;
            int i8 = i7 + 1;
            if (this.j) {
                iArr2 = this.e;
                if (iArr2[i7] != -1) {
                    i7 = iArr2.length;
                }
            } else {
                i7 = i8;
            }
            iArr2 = this.e;
            if (i7 >= iArr2.length && this.a < iArr2.length) {
                i8 = 0;
                while (true) {
                    int[] iArr4 = this.e;
                    if (i8 >= iArr4.length) {
                        break;
                    } else if (iArr4[i8] == -1) {
                        i7 = i8;
                        break;
                    } else {
                        i8++;
                    }
                }
            }
            iArr2 = this.e;
            if (i7 >= iArr2.length) {
                i7 = iArr2.length;
                i8 = this.d * 2;
                this.d = i8;
                this.j = false;
                this.i = i7 - 1;
                this.g = Arrays.copyOf(this.g, i8);
                this.e = Arrays.copyOf(this.e, this.d);
                this.f = Arrays.copyOf(this.f, this.d);
            }
            this.e[i7] = gVar.b;
            this.g[i7] = f;
            if (i4 != -1) {
                iArr = this.f;
                iArr[i7] = iArr[i4];
                iArr[i4] = i7;
            } else {
                this.f[i7] = this.h;
                this.h = i7;
            }
            gVar.l++;
            gVar.a(this.b);
            this.a++;
            if (!this.j) {
                this.i++;
            }
            i2 = this.i;
            iArr = this.e;
            if (i2 >= iArr.length) {
                this.j = true;
                this.i = iArr.length - 1;
            }
        }
    }

    public final float c(g gVar) {
        int i = this.h;
        int i2 = 0;
        while (i != -1 && i2 < this.a) {
            if (this.e[i] == gVar.b) {
                return this.g[i];
            }
            i = this.f[i];
            i2++;
        }
        return 0.0f;
    }

    public final void clear() {
        int i = this.h;
        int i2 = 0;
        while (i != -1 && i2 < this.a) {
            g gVar = this.c.d[this.e[i]];
            if (gVar != null) {
                gVar.b(this.b);
            }
            i = this.f[i];
            i2++;
        }
        this.h = -1;
        this.i = -1;
        this.j = false;
        this.a = 0;
    }

    public boolean d(g gVar) {
        int i = this.h;
        if (i == -1) {
            return false;
        }
        int i2 = 0;
        while (i != -1 && i2 < this.a) {
            if (this.e[i] == gVar.b) {
                return true;
            }
            i = this.f[i];
            i2++;
        }
        return false;
    }

    public int e() {
        return this.a;
    }

    public float f(b bVar, boolean z) {
        float c = c(bVar.a);
        h(bVar.a, z);
        b.g.b.b.a aVar = bVar.d;
        int e = aVar.e();
        for (int i = 0; i < e; i++) {
            g i2 = aVar.i(i);
            b(i2, aVar.c(i2) * c, z);
        }
        return c;
    }

    public final void g(g gVar, float f) {
        if (f == 0.0f) {
            h(gVar, true);
            return;
        }
        int i = this.h;
        int i2;
        int[] iArr;
        if (i == -1) {
            this.h = 0;
            this.g[0] = f;
            this.e[0] = gVar.b;
            this.f[0] = -1;
            gVar.l++;
            gVar.a(this.b);
            this.a++;
            if (!this.j) {
                i2 = this.i + 1;
                this.i = i2;
                iArr = this.e;
                if (i2 >= iArr.length) {
                    this.j = true;
                    this.i = iArr.length - 1;
                }
            }
            return;
        }
        int[] iArr2;
        int[] iArr3;
        int i3 = 0;
        int i4 = -1;
        while (i != -1 && i3 < this.a) {
            iArr2 = this.e;
            int i5 = iArr2[i];
            int i6 = gVar.b;
            if (i5 == i6) {
                this.g[i] = f;
                return;
            }
            if (iArr2[i] < i6) {
                i4 = i;
            }
            i = this.f[i];
            i3++;
        }
        i = this.i;
        i3 = i + 1;
        if (this.j) {
            iArr3 = this.e;
            if (iArr3[i] != -1) {
                i = iArr3.length;
            }
        } else {
            i = i3;
        }
        iArr3 = this.e;
        if (i >= iArr3.length && this.a < iArr3.length) {
            i3 = 0;
            while (true) {
                iArr2 = this.e;
                if (i3 >= iArr2.length) {
                    break;
                } else if (iArr2[i3] == -1) {
                    i = i3;
                    break;
                } else {
                    i3++;
                }
            }
        }
        iArr3 = this.e;
        if (i >= iArr3.length) {
            i = iArr3.length;
            i3 = this.d * 2;
            this.d = i3;
            this.j = false;
            this.i = i - 1;
            this.g = Arrays.copyOf(this.g, i3);
            this.e = Arrays.copyOf(this.e, this.d);
            this.f = Arrays.copyOf(this.f, this.d);
        }
        this.e[i] = gVar.b;
        this.g[i] = f;
        if (i4 != -1) {
            iArr = this.f;
            iArr[i] = iArr[i4];
            iArr[i4] = i;
        } else {
            this.f[i] = this.h;
            this.h = i;
        }
        gVar.l++;
        gVar.a(this.b);
        i2 = this.a + 1;
        this.a = i2;
        if (!this.j) {
            this.i++;
        }
        iArr = this.e;
        if (i2 >= iArr.length) {
            this.j = true;
        }
        if (this.i >= iArr.length) {
            this.j = true;
            this.i = iArr.length - 1;
        }
    }

    public final float h(g gVar, boolean z) {
        int i = this.h;
        if (i == -1) {
            return 0.0f;
        }
        int i2 = 0;
        int i3 = -1;
        while (i != -1 && i2 < this.a) {
            if (this.e[i] == gVar.b) {
                if (i == this.h) {
                    this.h = this.f[i];
                } else {
                    int[] iArr = this.f;
                    iArr[i3] = iArr[i];
                }
                if (z) {
                    gVar.b(this.b);
                }
                gVar.l--;
                this.a--;
                this.e[i] = -1;
                if (this.j) {
                    this.i = i;
                }
                return this.g[i];
            }
            i2++;
            i3 = i;
            i = this.f[i];
        }
        return 0.0f;
    }

    public g i(int i) {
        int i2 = this.h;
        int i3 = 0;
        while (i2 != -1 && i3 < this.a) {
            if (i3 == i) {
                return this.c.d[this.e[i2]];
            }
            i2 = this.f[i2];
            i3++;
        }
        return null;
    }

    public void j(float f) {
        int i = this.h;
        int i2 = 0;
        while (i != -1 && i2 < this.a) {
            float[] fArr = this.g;
            fArr[i] = fArr[i] / f;
            i = this.f[i];
            i2++;
        }
    }

    public void k() {
        int i = this.h;
        int i2 = 0;
        while (i != -1 && i2 < this.a) {
            float[] fArr = this.g;
            fArr[i] = fArr[i] * -1.0f;
            i = this.f[i];
            i2++;
        }
    }

    public String toString() {
        int i = this.h;
        String str = "";
        int i2 = 0;
        while (i != -1 && i2 < this.a) {
            StringBuilder g = c.b.a.a.a.g(c.b.a.a.a.D(str, " -> "));
            g.append(this.g[i]);
            g.append(" : ");
            g = c.b.a.a.a.g(g.toString());
            g.append(this.c.d[this.e[i]]);
            str = g.toString();
            i = this.f[i];
            i2++;
        }
        return str;
    }
}
